﻿using System;
using System.Xml.Linq;

namespace Lightray.Hattrick.ChppLib.EntityTypes
{
    public class Economy
    {
        #region Properties

        public int Cash { get; private set; }
        public int ExpectedCash { get; private set; }
        public SponsorsMood SponsorsPopularity { get; private set; }
        public SupportersMood SupportersPopularity { get; private set; }
        public int FanClubSize { get; private set; }
        public int IncomeSpectators { get; private set; }
        public int IncomeSponsors { get; private set; }
        public int IncomeFinancial { get; private set; }
        public int IncomeSoldPlayers { get; private set; }
        public int IncomeSoldPlayersCommission { get; private set; }
        public int IncomeTemporary { get; private set; }
        public int IncomeSum { get; private set; }
        public int CostsArena { get; private set; }
        public int CostsPlayers { get; private set; }
        public int CostsFinancial { get; private set; }
        public int CostsStaff { get; private set; }
        public int CostsBoughtPlayers { get; private set; }
        public int CostsArenaBuilding { get; private set; }
        public int CostsTemporary { get; private set; }
        public int CostsYouth { get; private set; }
        public int CostsSum { get; private set; }
        public int ExpectedWeeksTotal { get; private set; }
        public int LastIncomeSpectators { get; private set; }
        public int LastIncomeSponsors { get; private set; }
        public int LastIncomeFinancial { get; private set; }
        public int LastIncomeSoldPlayers { get; private set; }
        public int LastIncomeSoldPlayersCommission { get; private set; }
        public int LastIncomeTemporary { get; private set; }
        public int LastIncomeSum { get; private set; }
        public int LastCostsArena { get; private set; }
        public int LastCostsPlayers { get; private set; }
        public int LastCostsFinancial { get; private set; }
        public int LastCostsStaff { get; private set; }
        public int LastCostsBoughtPlayers { get; private set; }
        public int LastCostsArenaBuilding { get; private set; }
        public int LastCostsTemporary { get; private set; }
        public int LastCostsYouth { get; private set; }
        public int LastCostsSum { get; private set; }
        public int LastWeeksTotal { get; private set; }

        internal int TeamID { get; private set; }
        #endregion

        private Economy() { }

        public static Economy FromXml(XDocument economyXml)
        {
            HattrickXmlReader reader = new HattrickXmlReader(economyXml);
            return new Economy()
            {
                TeamID = reader.ReadNumber("TeamID"),

                Cash = reader.ReadNumber("Cash"),
                ExpectedCash = reader.ReadNumber("ExpectedCash"),
                SponsorsPopularity = reader.ReadSponsorsMood("SponsorsPopularity"),
                SupportersPopularity = reader.ReadSupportersMood("SupportersPopularity"),
                FanClubSize = reader.ReadNumber("FanClubSize"),
                IncomeSpectators = reader.ReadNumber("IncomeSpectators"),
                IncomeSponsors = reader.ReadNumber("IncomeSponsors"),
                IncomeFinancial = reader.ReadNumber("IncomeFinancial"),
                IncomeSoldPlayers = reader.ReadNumber("IncomeSoldPlayers"),
                IncomeSoldPlayersCommission = reader.ReadNumber("IncomeSoldPlayersCommission"),
                IncomeTemporary = reader.ReadNumber("IncomeTemporary"),
                IncomeSum = reader.ReadNumber("IncomeSum"),
                CostsArena = reader.ReadNumber("CostsArena"),
                CostsPlayers = reader.ReadNumber("CostsPlayers"),
                CostsFinancial = reader.ReadNumber("CostsFinancial"),
                CostsStaff = reader.ReadNumber("CostsStaff"),
                CostsBoughtPlayers = reader.ReadNumber("CostsBoughtPlayers"),
                CostsArenaBuilding = reader.ReadNumber("CostsArenaBuilding"),
                CostsTemporary = reader.ReadNumber("CostsTemporary"),
                CostsYouth = reader.ReadNumber("CostsYouth"),
                CostsSum = reader.ReadNumber("CostsSum"),
                ExpectedWeeksTotal = reader.ReadNumber("ExpectedWeeksTotal"),
                LastIncomeSpectators = reader.ReadNumber("LastIncomeSpectators"),
                LastIncomeSponsors = reader.ReadNumber("LastIncomeSponsors"),
                LastIncomeFinancial = reader.ReadNumber("LastIncomeFinancial"),
                LastIncomeSoldPlayers = reader.ReadNumber("LastIncomeSoldPlayers"),
                LastIncomeSoldPlayersCommission = reader.ReadNumber("LastIncomeSoldPlayersCommission"),
                LastIncomeTemporary = reader.ReadNumber("LastIncomeTemporary"),
                LastIncomeSum = reader.ReadNumber("LastIncomeSum"),
                LastCostsArena = reader.ReadNumber("LastCostsArena"),
                LastCostsPlayers = reader.ReadNumber("LastCostsPlayers"),
                LastCostsFinancial = reader.ReadNumber("LastCostsFinancial"),
                LastCostsStaff = reader.ReadNumber("LastCostsStaff"),
                LastCostsBoughtPlayers = reader.ReadNumber("LastCostsBoughtPlayers"),
                LastCostsArenaBuilding = reader.ReadNumber("LastCostsArenaBuilding"),
                LastCostsTemporary = reader.ReadNumber("LastCostsTemporary"),
                LastCostsYouth = reader.ReadNumber("LastCostsYouth"),
                LastCostsSum = reader.ReadNumber("LastCostsSum"),
                LastWeeksTotal = reader.ReadNumber("LastWeeksTotal")
            };
        }

        public override string ToString()
        {
            return string.Format("{0} ({1})", Cash, ExpectedCash);
        }
    }
}